package com.young.serial.listener;

import com.young.serial.utils.ConvertHexStrAndStrUtils;
import com.young.serial.utils.SerialPortManager;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: Young
 * @CreateTime: 2025-01-14
 * @Description:
 * @Version: 1.0
 */
public class SerialPortCallback {
    public void dataAvailable() {
        try {
            //当前监听器监听到的串口返回数据 back
            byte[] back = SerialPortManager.readSerialPortData();
            System.out.println("back-"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))+"--"+ ConvertHexStrAndStrUtils.bytesToHexStr(back));
            String s = ConvertHexStrAndStrUtils.bytesToHexStr(back);
            System.out.println("rev--data:"+s);
            //throw new Exception();
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
}
